package org.example.TankGan.pojo.MyHeroTank;

import lombok.AllArgsConstructor;
import lombok.Data;
import org.example.TankGan.pojo.Bullet.Bullet;
import org.example.TankGan.pojo.Tank;
import org.example.Utils.ShootBulletUtlis;

import java.util.Vector;

/**
 * @author cc
 * @date 2021/4/17 11:30
 * @Description
 */
@Data
@AllArgsConstructor
public class MyHero extends Tank {
    //定义一个子弹类
    private Bullet bullet =null ;
    //定义多个子弹类
    private Vector<Bullet> bullets=null;
    //定义最多少个子弹
    private int NumBullet=1;
    private int BulletSpeed;
    private boolean istrue=true;

    public MyHero(int x, int y, int drection, int speed) {
        super(x, y, drection, speed);
    }

    public MyHero(int x, int y, int drection, int speed, int type) {
        super(x, y, drection, speed, type);
    }

    public MyHero(int x, int y, int drection, int speed, int type, int numBullet) {
        super(x, y, drection, speed, type);
        this.NumBullet=numBullet;
        JudgeBuller();
    }

    public MyHero(int numBullet) {
        NumBullet = numBullet;
    }

    public MyHero() {
        JudgeBuller();
    }

    public MyHero(int x, int y, int drection, int speed, int type, int numBullet, int bulletSpeed) {
        super(x, y, drection, speed, type);
        NumBullet = numBullet;
        BulletSpeed = bulletSpeed;
    }

    public void JudgeBuller(){
        if (NumBullet>1){
           ShutManyBullet();
        }else {
            ShutBullet();
        }
    }
    //射击
    public Bullet ShutBullet(){
        int bullet_speeed=this.getSpeed()+getBulletSpeed();
        /**废弃方法**/
//        int bullet_speeed=1;
        //根据方向
//        switch (getDrection()){
//            case 0: //上
//                 bullet = new Bullet(getX() + 20, getY() + 10, 0, bullet_speeed);
//                 break;
//            case 1://右
//                bullet = new Bullet(getX()+60,getY()+20,1,bullet_speeed);
//                break;
//            case 2://下
//                bullet = new Bullet(getX()+20,getY()+60,2,bullet_speeed);
//                break;
//            case 3://左
//                bullet = new Bullet(getX(),getY()+20,3,bullet_speeed);
//                break;
//        }
        Vector<Bullet> shut = ShootBulletUtlis.Shut(getX(), getY(), getDrection(), bullet_speeed, NumBullet);
        //启动线程
        for (int i = 0; i < shut.size(); i++) {
            bullet = shut.get(i);
            new Thread(bullet).start();
        }
        return bullet;
    }

    //多个子弹射击
    public void ShutManyBullet(){
        if (bullets==null){
            bullets = new Vector<Bullet>(NumBullet);
        }else {
            if (bullets.size()==NumBullet){
                return;
            }
            Bullet bullet = ShutBullet();
            bullets.add(bullet);
        }
    }
}
